package com.real.operationalcontrols.适配器;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.real.operationalcontrols.R;
import com.real.operationalcontrols.任务.TaskInfoActivity;
import com.real.operationalcontrols.任务.TaskMainActivity;
import com.real.operationalcontrols.实体类.WaringListBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class TaskNoAdapter extends RecyclerView.Adapter<TaskNoAdapter.ViewHolder> {
    Context context;
    List<WaringListBean.TasklistBean> data = new ArrayList<>();

    public TaskNoAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<WaringListBean.TasklistBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_task_no,
                viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvMessageTitle.setText(data.get(position).getAddress());
        holder.tvMessageContext.setText("报警时间：" + data.get(position).getTime());
        if (data.get(position).getStatus().contains("进行")) {
            holder.imgArlm.setImageResource(R.mipmap.jinxingzhong);
        } else {
            holder.imgArlm.setImageResource(R.mipmap.weiwancheng);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (data.get(position).getStatus().contains("未接受")) {
                    Intent i = new Intent(context, TaskMainActivity.class);
                    i.putExtra("id", data.get(position).getId());
                    context.startActivity(i);
                }
                if (data.get(position).getStatus().contains("进行")) {
                    Intent i = new Intent(context, TaskInfoActivity.class);
                    i.putExtra("id", data.get(position).getId());
                    context.startActivity(i);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_arlm)
        ImageView imgArlm;
        @BindView(R.id.tv_message_title)
        TextView tvMessageTitle;
        @BindView(R.id.tv_message_context)
        TextView tvMessageContext;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
